#include "types.hpp"
#include "system.hpp"


#ifndef PIC_HPP
#define PIC_HPP

namespace system {

    extern byte pic1_interrupt_offset;
    extern byte pic2_interrupt_offset;

    const byte pic1_command = 0x20;
    const byte pic1_data    = 0x21;
    const byte pic2_command = 0xA0;
    const byte pic2_data    = 0xA1;

    const byte pic_command_end_of_interrupt = 0x20;

    inline void pic1_end_of_interrupt(){ outportb(pic1_command,pic_command_end_of_interrupt); }
    inline void pic2_end_of_interrupt(){ outportb(pic2_command,pic_command_end_of_interrupt); pic1_end_of_interrupt(); }

    inline void pic_end_of_interrupt(byte irq){ if(irq >= 8) pic2_end_of_interrupt(); else pic1_end_of_interrupt(); }

    void init_pic(byte pic1_interrupt_offset, byte pic2_interrupt_offset);

    inline void init_pic(byte interrupt_offset = 0x20){ init_pic(interrupt_offset,interrupt_offset+8); }

}

#endif // PIC_HPP
